package org.ethan.order.controller;

import org.ethan.basic.exception.BasicException;
import org.ethan.basic.util.AjaxResult;
import org.ethan.order.dto.OrderDto;
import org.ethan.order.service.IOrderPetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 订单相关controller
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private IOrderPetService orderPetService;

    /**
     * 保存用户提交的订单信息
     * @param dto
     * @return
     */
    @PostMapping("/saveSubmit")
    public AjaxResult submitOrder(@RequestBody OrderDto dto) {
        try {
             String orderNum = orderPetService.submitOrder(dto);
            return AjaxResult.me().setResultObj(orderNum);
        } catch (BasicException e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("System Failure");
        }

    }

}
